Fix sleep session splitting across midnight boundary#15
Open
hoveeman wants to merge 5 commits into
Open
Conversation
Group sleep packets using a noon-to-noon boundary (12:00 PM to 12:00 PM) instead of start-of-day. This prevents a single night's sleep that starts before midnight from being split into two database sessions, ensuring the pre-midnight portion correctly shows up on the morning's waking day.
1a19404 to
1bb529c
Compare
…it deinit testCrossMidnightSleepMerging crashed the CI test runner with SIGABRT (a libmalloc double-free), which also got mis-attributed to the adjacent testBlocksOnlyForDayRange. The crash log points at EventPersistenceSubscriber.__deallocating_deinit -> swift_task_deinitOnExecutorMainActorBackDeploy: the synthesized main-actor deinit hops through a back-deploy shim that double-frees on iOS < 26.5, which is the runtime the GitHub runner uses (it ran on iOS 18.6 here). Production is unaffected because the app keeps a single subscriber alive for its lifetime; only a unit test that creates and drops one triggers the dealloc path. Adding an explicit (non-isolated) deinit avoids the buggy executor-hop codegen and also cancels the outstanding event/flush tasks, which is correct hygiene. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently, sleep packets are grouped into database sessions using the packet's start date (via calendar.startOfDay). If a user falls asleep before midnight (e.g., 11:30 PM), the sleep blocks before midnight are stored in a session dated yesterday, while blocks after midnight are stored in today's session. Since the Today view only queries for today's session date, the pre-midnight portion is hidden, making it look like sleep was only calculated from 12:00 AM on.
This PR changes the grouping logic to use a noon-to-noon boundary, mapping sleep starting at or after 12:00 PM to the next day's waking morning. This unifies the entire night's sleep under a single session dated on the morning of waking.
An integration unit test has been added to verify the cross-midnight merging behavior.